<?php

namespace app\admin\controller\merchant;
/**
 *  @icon fa fa-activity-balance
 **/
class ActivityBalance extends Base
{
	/**
     * @var \app\admin\model\User
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = loadModel('ActivityBalance');
    }


	//余额充值活动列表
    public function index()
    {
        if ($this->request->isAjax()) {
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $list = $this->model
                ->where($where)
                ->order($sort, $order)
                ->paginate($limit);
            $result = array("total" => $list->total(), "rows" => $list->items());
            return json($result);
        }
        return $this->view->fetch();
    }

    public function add() {
    	if ($this->request->isAjax()) {
    		$post = loader('admin')->loadAny('request', 'ActivityBalance')->row();
    		$this->model->allowField(true)->save($post);
    		$this->success();
    	}
    	return $this->view->fetch();
    }

    public function edit($ids = null) {
        $row = $this->model->find($ids);
        if ($this->request->isAjax()) {
            $post = loader('admin')->loadAny('request', 'ActivityBalance')->row();
            $row->save($post);
            $this->success();
        }
        $this->assign('row', $row);
        return $this->view->fetch();
    }

}
